package servlet.PersonServlet;

import dao.PersonDAO;
import entity.PersonBean;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import myUtil.personCheck;

import java.io.IOException;

@WebServlet("/PersonEditServlet")
public class PersonEditServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int i = 0;
        if (req.getParameter("id") != null) {
            String I = req.getParameter("id");
            i = Integer.parseInt(I);
        }
        PersonBean personBean;
        if(req.getAttribute("personBean")!=null){
            personBean = (PersonBean) req.getAttribute("personBean");
        }else{
            PersonDAO dao = new PersonDAO();
            personBean = dao.findTaskBean(i);
        }
        req.setAttribute("personBean", personBean);
        req.getRequestDispatcher("person_edit.jsp").forward(req, resp);
    }
}
